import datetime
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from applications.extensions import db

class Member(db.Model):
    __tablename__ = 'admin_member'
    id = db.Column(db.Integer, primary_key=True, comment='用户ID')
    username = db.Column(db.String(255), comment='用户名')
    memberrole_id = db.Column(db.String(255), comment='角色组id')
    enable = db.Column(db.Integer, default=1, comment='在职状态 1:在职0：离职')
    type = db.Column(db.Integer, default=0,comment='考试状态 1:合格2：不合格')
    remark = db.Column(db.String(255), comment='备注')
    password_hash = db.Column(db.String(128), comment='哈希密码')
    mailbox = db.Column(db.String(255), comment='邮箱')
    name = db.Column(db.String(255), comment='角色组名')
    sort = db.Column(db.Integer,default=1, comment='排序')
    create_time = db.Column(db.DateTime, default="", comment='注册时间')
    update_time = db.Column(db.DateTime, default="", onupdate=datetime.datetime.now, comment='更新时间')



    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def validate_password(self, password):
        return check_password_hash(self.password_hash, password)
